﻿using System;
using System.Data;

namespace UdpAuthorizationService.Core.Logging
{
	public abstract class LoggingFacade
	{
		#region Singleton
		
		private static Lazy<LoggingFacade> _logger = null;
		public static LoggingFacade Logger
		{
			get
			{
				if (_logger == null)
					throw new ApplicationException("Logger is not registered");

				return _logger.Value;
			}
		}

		public static void RegisterLogger<T>() where T : LoggingFacade, new()
		{
			if (_logger != null && _logger.IsValueCreated)
				throw new ConstraintException("Logger is already created");

			_logger = new Lazy<LoggingFacade>(() => new T());
		}

		#endregion

		public abstract void Log(LogEvent logEvent);
	}
}
